package com.wnxy.pawnbackgroundsystem.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wnxy.pawnbackgroundsystem.entity.Assess;
import com.wnxy.pawnbackgroundsystem.entity.Goods;
import com.wnxy.pawnbackgroundsystem.param.assessParam.AssessParam;
import com.wnxy.pawnbackgroundsystem.param.assessParam.GetAssess;
import com.wnxy.pawnbackgroundsystem.param.goodsParam.GoodsParam;
import com.wnxy.pawnbackgroundsystem.response.Result;
import com.wnxy.pawnbackgroundsystem.service.IAssessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 评估历史表 前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2021-10-17
 */
@RestController
@RequestMapping("/assess")
@Slf4j
@CrossOrigin("*")
public class AssessController {

    @Resource
    private IAssessService assessService;

    @GetMapping("queryAllAssess")
    public Result<Goods> queryAllGoods(GoodsParam goodsParam,
              @RequestParam(name = "pageSize",defaultValue = "10") int pageSize
            , @RequestParam(name = "current",defaultValue = "1") int current){
        log.info("查询所有商品控制层：查询所有商品信息");
        IPage byPage = assessService.findAllAssessByPage( goodsParam.getGoodsId(),pageSize, current);
        log.info("查询所有商品控制层,返回前端的参数bypage:{}",byPage.getRecords());
//        if(byPage!=null) {
//            return Result.success(Assess.class,byPage);
//        }
//        return Result.fail("500","查询为空");
        return Result.success(Assess.class,byPage);
    }
    @PostMapping("addAssess")
    public Result addAssess(@RequestBody GetAssess getAssess){
        log.info("估价商品功能： 参数={}",getAssess);
        Integer i = assessService.assessTure(getAssess.getAssessParam());
        if(i>0){
            return Result.success("已评估");
        }
        return Result.fail("502","鉴定商品失败");
    }



}

